<template>
  <hips-view>
    <hips-nav-bar
      slot="header"
      title="Switch 开关"
      :back-button="{
        showLeftArrow: true,
      }"
      @nav-bar-back-click="$router.back()"
    />

    <hips-tabs
      slot="sub-header"
      v-model="active"
    >
      <hips-tab title="标准用法" />
      <hips-tab title="Dsx用法" />
    </hips-tabs>

    <div v-show="!active">
      <demo-block title="基础用法">
        <hips-switch
          v-model="checked1"
          checked-text="在线"
          unchecked-text="离线"
          width="80"
        />        
      </demo-block>

      <demo-block title="禁用">
        <hips-switch
          v-model="checked2"
          disabled
        />
      </demo-block>

      <demo-block title="加载中">
        <hips-switch
          v-model="checked3"
          loading
        />
        <hips-switch
          v-model="checked4"
          loading
        />
      </demo-block>

      <demo-block title="高级用法">
        <hips-switch
          v-model="checked5"
          @change="onChange"
        />        
      </demo-block>
    </div>
    <div v-show="active">
      <demo-block title="基础用法">
        <hips-switch :d-field="dsx.records.at(0).getField('checked1')" />        
      </demo-block>

      <demo-block title="禁用">
        <hips-switch :d-field="dsx.records.at(0).getField('checked2')" />
      </demo-block>

      <demo-block title="加载中">
        <hips-switch :d-field="dsx.records.at(0).getField('checked3')" />
        <hips-switch :d-field="dsx.records.at(0).getField('checked4')" />
      </demo-block>

      <demo-block title="高级用法">
        <hips-switch :d-field="dsx.records.at(0).getField('checked5')" />
      </demo-block>
    </div>
  </hips-view>
</template>

<script>
import BasicView from '@/mixin/basic-view';
import { Switch, Tabs, Tab } from '@hips/vue-ui';
import Dsx from '@hips/plugin-dataset-vuex';

export default {
  components: {
    [Switch.name]: Switch,
    [Tabs.name]: Tabs,
    [Tab.name]: Tab,
  },
  mixins: [ BasicView ],
  data() {
    const _this = this;
    return {
      active: 0,
      checked1: true,
      checked2: true,
      checked3: false,
      checked4: true,
      checked5: true,
      dsx: new Dsx({
        moduleName: 'dsx-switch',
        autoCreate: true,
        fields: [
          {
            name: 'checked1',
            defaultValue: true,
            checkedText: '在线',
            uncheckedText: '离线',
            width: 80,
          },
          {
            name: 'checked2',
            disabled: true,
          },
          {
            name: 'checked3',
            defaultValue: true,
            loading: true,
          },
          {
            name: 'checked4',
            defaultValue: false,
            loading: true,
          },
          {
            name: 'checked5',
            defaultValue: false,
            emits: {
              change(ev) {
                _this.$hips.toast('dsx checked = ' + ev);
              },
            },
          },
        ],
      }),
    };
  },

  methods: {
    onChange(checked) {
      this.$hips.toast(checked);
    },
  },
};
</script>

<style lang="stylus" scoped>
>>> .demo-block {
    .wrapper {
        padding 10px
    }
}
</style>
